<?php
class ErrorsClass {
	var $errors = array();
	
	function AddError($err_code, $module=""){
		if ($module == "") $this->errors[$err_code]=$err_code;
		else {
			$this->errors[$err_code]=$err_code;
			$this->errors[$module][$err_code]=$err_code;
			if ((isset($_POST['form_id']) && (strlen($_POST['form_id'])>0)) or
				(isset($_GET['form_id']) && (strlen($_GET['form_id'])>0))
				) $this->errors['form_id'][$_POST['form_id']]=$err_code;
		}
		$this->SaveErrorSession();
	}	
	function GetErrorArray(){
		return $this->errors;	
	}
	function GetErrorSerial(){
		return serialize($this->GetErrorArray());
	}
	function SaveErrorSession(){
		$_SESSION['errors'] = $this->GetErrorSerial();
	}
	function DeleteErrorSession($module=""){
		if ($module == "") $_SESSION['errors'] = NULL;
		else $_SESSION['errors'][$module] = NULL;
	}
	function LoadErrorArray($params){
		if (isset($_SESSION['errors']) && $_SESSION['errors']!=NULL) {
			if(isset($params['module'])){
				$errors=unserialize($_SESSION['errors'][$params['module']]);
				if(!isset($params['save'])) $this->DeleteErrorSession($params['module']);
				return $errors;
			} else {
				$errors=unserialize($_SESSION['errors']);
				if(!isset($params['save'])) $this->DeleteErrorSession();
				return $errors;
			}
		}		
		else return false;
	}
}
?>
